import React, {  } from 'react'
import moment from 'moment'
import { Table } from 'antd';

const DateFormat='YYYY-MM-DD hh:mm:ss'
export default function MyTable(props) {

  const {data,role,setRole}=props

  const columns = [
    {
      title: '角色名称',
      dataIndex: 'name',
      width:'23%',
      align:'center',
    },
    {
      title: '创建时间',
      dataIndex: 'create_time',
      width:'23%',
      align:'center',
      render:res=>moment(res).format(DateFormat)
    },
    {
      title: '授权时间',
      dataIndex: 'auth_time',
      align:'center',
      width:'23%',
      render:res=>res?moment(res).format(DateFormat):''
    },
    {
      title: '授权人',
      dataIndex: 'auth_name',
      align:'center',
      width:'23%'
    }
  ]

  const onSelect=(selected)=>{
    setRole(selected)
  }

  return (
    <Table 
    columns={columns} 
    dataSource={data} 
    bordered rowKey="_id" 
    rowSelection={{type:'radio',width:'8%',onSelect,selectedRowKeys:[role._id]}} 
    onRow={record=>({onClick:()=>setRole(record)})}/>
  )
}
